<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      li {
        list-style-type: none;
        border: 1px #000 solid;
        width: 60px;
        background-color: #fff;
      }
      ul {
        margin: auto;
        display: none;
      }
      .box {
        margin: 0 auto;
        width: 60px;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <button onclick="show()">输入法</button>
      <ul id="ul">
        <li class="li">简写</li>
        <li class="li">拼音</li>
        <li class="li" onclick="out()">关闭</li>
      </ul>
    </div>
  </body>
</html>
<script>
  var dom = document.getElementById("ul");
  var li = document.querySelectorAll(".li");
  console.log(li);
  function show() {
    dom.style.cssText = "display:block";
  }
  for (let i = 0; i < li.length; i++) {
    li[i].onmouseover = function () {
      this.style.backgroundColor = "red";
    };
    li[i].onmouseout = function () {
      this.style.backgroundColor = "";
    };
    li[2].onclick = function () {
      dom.style.cssText = "display:none";
    };
  }
</script>
